#include <iostream>
using namespace std;
int main()
{
	int total,num_1,price_1,num_2,price_2,num_3,price_3;
	int i,p1,p2,p3,min;
	int tag(int,int,int);
	cin>>total;
	cin>>num_1>>price_1;
	cin>>num_2>>price_2;
	cin>>num_3>>price_3;
	if (total,num_1,price_1,num_2,price_2,num_3,price_3 < 10000)
	{
		p1 = tag(total,num_1,price_1);
		p2 = tag(total,num_2,price_2);
		p3 = tag(total,num_3,price_3);
		if (p1<p2)
		{
			if (p1<p3) min = p1;
			else min = p3;
		}
		else if (p1>p2)
		{
			if (p3>p2) min = p2;
			else min = p3;
		}
		cout<<min<<endl;
	}
	else cout<<"Error!"<<endl;
	return 0;
}

int tag(int a,int b,int c)
{
	int t,total;
	if (a%b==0) t = a / b;
	else t = a / b + 1;
	total = t * c;
	return total;
}
